package com.zhiwei.most.wear.utils;

/**
 * Create by zhiweizhu on 2022/3/1
 */

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

import com.blankj.utilcode.util.ResourceUtils;
import com.blankj.utilcode.util.Utils;
import com.zhiwei.most.R;


/**
 * Class containing helpers for querying wearable navigation pattern
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public final class WearableNavigationHelper {

    private static final String ITEM_NAME = "config_windowSwipeToDismiss";
    private static final String ITEM_TYPE = "bool";
    private static final String PACKAGE_NAME = "android";

    private WearableNavigationHelper() {
    }

    /**
     * Query whether swipe-to-dismiss is enabled on current device.
     */
    public static boolean isSwipeToDismissEnabled() {
        final Resources res = Resources.getSystem(); // system resources
        final int identifier = res.getIdentifier(ITEM_NAME, ITEM_TYPE, PACKAGE_NAME);
        if (identifier != 0) {
            return res.getBoolean(identifier);
        }
        return false;
    }

    /**
     * Query whether swipe-to-dismiss is enabled in current context.
     */
    @SuppressWarnings("deprecation")
    public static boolean isSwipeToDismissEnabled(@NonNull Context context) {
        /*TypedArray windowAttr =
                context.obtainStyledAttributes(new int[]{android.R.attr.windowSwipeToDismiss});
        boolean enabled = false;
        if (windowAttr.getIndexCount() > 0) {
            enabled = windowAttr.getBoolean(0, true);
        }
        windowAttr.recycle();*/
        return Utils.getApp().getResources().getBoolean(R.bool.is_windows_swipe_to_dismiss);
    }
}
